<?php echo $this->render($this->includeDir . '/toolbar.php');?>
<?php echo $this->flashMessage();?>
<?php 
	$arrParam = $this->arrParam;
	
	$name 		= $this->formText('name',$this->Item['name'],array('class'=>'width-300 bg-green2 floatLeft' ));
	$parentValue = $this->Item['parents']>0?$this->Item['parents']:1;
	$parents	= $this->cmsSelect('parents', $parentValue,array('class'=>'width-150','size'=>10), $this->slbParents);
	$image 		= $this->formFile('image',array('class'=>'floatLeft'));
	$ordering	= $this->formText('ordering',$this->Item['ordering'],array('class'=>'width-150 floatLeft'));
	
	$content			= Zendvn_Filter_Filter::filterContent($this->Item['content'],'filter');
	$content			= $this->tinyMce('content',$content,array('style'=>"width: 100%; height: 350px;"));
	$content			= '<div id="d_content" style="width:98%; float: left">' . $content . '</div>';
	
	$html_descript = $this->formTextarea('html_descript',$this->Item['html_descript'],array('class'=>'floatLeft','rows'=>8));
	$html_keyword = $this->formTextarea('html_keyword',$this->Item['html_keyword'],array('class'=>'floatLeft','rows'=>8));
	
	$options 	= array('inactive'=>$this->translate('Inactive'),'active'=>$this->translate('Active'));	
	$status 	= $this->formSelect('status',$this->Item['status'],array('class'=>'width-150'),$options);
	
	$formHelp = '';
	$arrTooltip = array(
						'name'=>"Name of category.",
						'parents'=>"Parent of category",
						'd_content'=>"Content of category",
						'html_descript'=>"Content of meta description for SEO",
						'html_keyword'=>"Content of meta keyword for SEO",
						'image'=>"Picture of category",
						'ordering'=>'Ordering of category',
						'status'=>'Status of category',
						);
	if(count($arrTooltip)>0){
		foreach ($arrTooltip as $key => $val){
			$attribs = array();
			if($key=='d_content') $attribs = array('leftOffset'=>-305);
			$formHelp  .= $this->cmsFormHelp('.form-table #' . $key, $this->translate($val), $attribs);	
		}
	}
	
	 if(count($this->errors)>0){	
	 	foreach ($this->errors as $key => $val){	 		
	 		$$key .= $this->cmsError($key,$val);	
	 		$selector = '.form-table #' . $key . '-error';
	 		$options = array('type'=>'error','name'=>'#' .$key);
	 		$formHelp  .= $this->cmsFormHelp($selector, $this->translate($val),null,$options);
	 		
	 	}
	 }

	 if($this->arrParam['action'] == 'edit'){
	 	$config = new Zendvn_Controller_Config(array('module'=>$arrParam['module'],
												'fileConfig'=>'product-category.ini'));
	 	
	 	$imageConfig 		= $config->getConfig('category');
		$current_image 		= '<div id="load-content-image" class="clr width-150 center">';
		if(!empty($this->Item['image'])){
			$imageUrl 		= $imageConfig['thumbUrl'] . '/' . $this->Item['image'];
			$removeLink 	= $this->url(array('action'=>'remove-pic','type'=>'image','file'=>$this->Item['image']));
			$current_image .= '<br>' . $this->cmsImage('image',$imageUrl,array('width'=>'75px'))
							. '<br><a  class="remove" href="javascript:loadPage(\'div#load-content-image\',\'' . $removeLink . '\')">remove</a>';
		}
		
		$current_image .= $this->formHidden('current_image',$this->Item['image'])
						. '</div>';
		$image .=	$current_image;
		
		/*========================================
		 * Background image
		 *========================================*/
		$current_bg_image 		= '<div id="load-content-bg-image" class="clr width-150 center">';
		if(!empty($this->Item['bg_image'])){
			$bgImageUrl 		= $imageConfig['uploadBgUrl'] . '/' . $this->Item['bg_image'];
			$removeLink 	= $this->url(array('action'=>'remove-pic','type'=>'bg-image','file'=>$this->Item['bg_image']));
			$current_bg_image .= '<br>' . $this->cmsImage('bg_image',$bgImageUrl,array('width'=>'75px'))
							. '<br><a  class="remove" href="javascript:loadPage(\'div#load-content-bg-image\',\'' . $removeLink . '\')">remove</a>';
		}
		
		$current_bg_image .= $this->formHidden('current_bg_image',$this->Item['bg_image'])
						. '</div>';
		$bg_image .=	$current_bg_image;
	}
	
	 $arrRow = array(
						array('label'=>$this->translate('Tên'),'input'=>$name),						
						array('label'=>$this->translate('Thể loại'),'input'=>$parents),						
						array('label'=>$this->translate('Hình ảnh'),'input'=>$image),
						array('label'=>$this->translate('Nội dung'),'input'=>$content),
						array('label'=>$this->translate('Mô tả Html'),'input'=>$html_descript),
						array('label'=>$this->translate('Từ khóa Html'),'input'=>$html_keyword),
						array('label'=>$this->translate('Trạng thái'),'input'=>$status),
						array('label'=>$this->translate('Thứ tự'),'input'=>$ordering),
	
					 );
	$tdForm = $this->partialLoop('row.php',$arrRow);
?>

<script type="text/javascript">
	$(document).ready(function() {
		<?php echo $formHelp;?>
	});
</script>
<div id="element-box">
	<div class="m">
		<div class="form-table">
            	<fieldset class="admin-fieldset">
                <legend class="admin-legend"><?php echo $this->translate('Form Detail')?></legend>
            	<table width="100%" border="0">
                	<?php echo $tdForm;?>
                </table>
                <div class="clr"></div>
                </fieldset>             
            </div>
            <div class="clr"></div>
	</div>
</div>
